//
//  UTString+Ext.swift
//  iPhoneUTests
//
//  Created by Toj on 11/20/23.
//

import XCTest

final class UTString_Ext: XCTestCase {

    override func setUpWithError() throws {
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }

    override func tearDownWithError() throws {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }

    func testExample() throws {
        print("-->UTests: start \n")
        
        // testCleanZero()
        testToK()
        
        print("-->UTests: end \n")
    }

    func testPerformanceExample() throws {
        // This is an example of a performance test case.
        self.measure {
            // Put the code you want to measure the time of here.
        }
    }
}

// UT Case
extension UTString_Ext {
    
    func testToK() {
        var count = 0
        var ck = count.to_k
        print("-->UTests: 0 to_k: \(ck)")
        
        count = 1
        ck = count.to_k
        print("-->UTests: 1 to_k: \(ck)")
        
        count = Int(arc4random_uniform(999)) + 1
        ck = count.to_k
        print("-->UTests: 1~999 to_k: \(ck)")
        
        count = 999
        ck = count.to_k
        print("-->UTests: 999 to_k: \(ck)")
        
        count = 1000
        ck = count.to_k
        print("-->UTests: 1000 to_k: \(ck)")
        
        count = Int(arc4random_uniform(1000)) + 1000
        ck = count.to_k
        print("-->UTests: 1000~999 to_k: \(ck)")
        
        count = Int(arc4random_uniform(11111111)) + 1000
        ck = count.to_k
        print("-->UTests: 1000+ to_k: \(ck)")
    }
    
    func testCleanZero() {
        test_cleanZero(decimal: "100.1.130")
        test_cleanZero(decimal: "100.1.00")
        test_cleanZero(decimal: "100.1")
        test_cleanZero(decimal: "100.1.100")
        test_cleanZero(decimal: "100.10")
        test_cleanZero(decimal: "1000")
        test_cleanZero(decimal: "1000.000000")
        
        let price: Double = 1033.60
        CM.absoluteTimes {
            print("-->UTests: 100.1.130: \("100.1.130".cm_cleanZero)")
            print("-->UTests: 100.1.00: \("100.1.00".cm_cleanZero)")
            print("-->UTests: 100.1: \("100.1".cm_cleanZero)")
            print("-->UTests: 100.1.100: \("100.1.100".cm_cleanZero)")
            print("-->UTests: 100.10: \("100.10".cm_cleanZero)")
            print("-->UTests: 1000: \("1000".cm_cleanZero)")
            print("-->UTests: \(price): \(price.mn_format.cm_cleanZero)")
        }
    }
    
    func test_cleanZero(decimal string: String) {
        let value = string.cm_cleanZero
        print("-->UTests: \(string) to value: " + value)
    }
}
